<?
include_once "accesscontrol.php";

if($submit == 'Delete')
{
	$q = "delete from job_education where uname = \"$_SESSION[uname]\" and En = \"$En\"  ";
	$r = mysql_query($q) or die(mysql_error());

	$q3 = "select * from job_education where uname = \"$_SESSION[uname]\" order by En asc ";
	$r3 = mysql_query($q3) or die(mysql_error());
		
	$q4 = "delete from job_education where uname = \"$_SESSION[uname]\" ";
	$r4 = mysql_query($q4) or die(mysql_error());	

	while($a3 = mysql_fetch_array($r3))
	{	
		$vn = $vn + 1;
		$q5 = "insert into job_education set
			uname = \"$_SESSION[uname]\", 
			En = \"$vn\", 
			E_i = \"$E_i\",
			E_Start = \"$a3[E_Start]\",
			E_End = \"$a3[E_End]\",
			E_gr = \"$a3[E_gr]\",
			E_d = \"$a3[E_d]\" ";
		
		$r5 = mysql_query($q5) or die(mysql_error());
	}

include_once "ER4.php";

}

elseif($submit == 'Edit')
{

$qe1 = "select * from job_education where uname = \"$_SESSION[uname]\" and En = \"$En\" ";
$re2 = mysql_query($qe1) or die(mysql_error());
$ae2 = mysql_fetch_array($re2);

$date1 = explode("/", $ae2[E_Start]);

$StartMonth = $date1[0];
$StartYear = $date1[1];

$date2 = explode("/", $ae2[E_End]);

$EndMonth = $date2[0];
$EndYear = $date2[1];

?>



<SCRIPT LANGUAGE="JavaScript">

function checkFields() {
missinginfo = "";

if (document.form.E_i.value == "") {
missinginfo += "\n     -  Institution name";
}
if (document.form.ESmonth.value == "") {
missinginfo += "\n     -  Start date / Month";
}
if (document.form.ESyear.value == "") {
missinginfo += "\n     -  Start date / Year";
}
if (document.form.EEmonth.value == "") {
missinginfo += "\n     -  End date / Month";
}
if (document.form.EEyear.value == "") {
missinginfo += "\n     -  End date / Year";
}
if (document.form.E_gr.value == "") {
missinginfo += "\n     -  Education level";
}
if (document.form.E_d.value == "") {
missinginfo += "\n     -  Description";
}

if(document.form.ESyear.value > document.form.EEyear.value) {
missinginfo += "\nSelect correct values for start and end years, please!";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}

</script>

<form method=post action=EditEE2.php   name=form onSubmit="return checkFields();">
<table align=center class=BlackText>

<tr>
	<td colspan=2 align=center class=HeaderClass><b>Education #<?=$En?></b></td>
</tr>

<tr>
	<td align=right><b>Institution name: </b></td>
	<td><input type=text name=E_i size=27 value="<? $ae2[E_i] = stripslashes($ae2[E_i]); echo $ae2[E_i]; ?>"></td>
</tr>

<tr>
	<td align=right><b>Start date: </b></td>

	<td>
	<select name=ESmonth>
	<option value=""> Month </option>
	<?
	for($i = 1; $i <= 12; $i++)
	{
		$m1 = date('F', mktime(0,0,0,$i,date(d),date(Y)));

		if($m1 == $StartMonth)
		{
			echo "<option value=\"$m1\" selected>$m1</option>\n\t";
		}
		else
		{
			echo "<option value=\"$m1\">$m1</option>\n\t";
		}
	}
	?>
	</select>


	<select name=ESyear style=width:74>
	<option value=""> Year &nbsp;&nbsp;&nbsp;&nbsp;</option>
	<?
	for($i = date(Y); $i >= (date(Y) - 70); $i--)
	{
		if($i == $StartYear)
		{
			echo "<option value=\"$i\" selected>$i</option>\n\t";
		}
		else
		{
			echo "<option value=\"$i\">$i</option>\n\t";
		}
	}
	?>

	</select>
	</td>
</tr>

<tr>
	<td align=right><b> End date: </b></td>

	<td>
	<select name=EEmonth>
	<option value=""> Month </option>
	<option value=Present class=Pres <? if($EndMonth == "Present") { echo "selected"; } ?>> Present </option>
	<?
	for($i = 1; $i <= 12; $i++)
	{
		$m1 = date('F', mktime(0,0,0,$i,date(d),date(Y)));

		if($m1 == $EndMonth)
		{
			echo "<option value=\"$m1\" selected>$m1</option>\n\t";
		}
		else
		{
			echo "<option value=\"$m1\">$m1</option>\n\t";
		}
	}
	?>
	</select>



	<select name=EEyear style=width:75>
	<option value=""> Year </option>
	<option value=Present class=Pres <? if($EndYear == "Present") { echo "selected"; } ?>>Present</option>
	<?
	for($i = date(Y); $i >= (date(Y) - 70); $i--)
	{
		if($i == $EndYear)
		{
			echo "<option value=\"$i\" selected>$i</option>\n\t";
		}
		else
		{
			echo "<option value=\"$i\">$i</option>\n\t";
		}
	}
	?>
	</select>
	</td>
</tr>

<tr> <td align=right><b>Professional: </b></td>
	
	<td>
	<select name="E_gr" style=width:174>
	<option value=""> Select </option>
	<?
		$gr = array("Student (High School)", "Collage", "Bachelor", "Master", "Ph D");

		while(list(,$v) = each($gr))
		{
			if($v == $ae2[E_gr])
			{
				echo "<option value=\"$v\" selected>$v</option>\n\t";
			}
			else
			{
				echo "<option value=\"$v\">$v</option>\n\t";
			}
		}
	?>
	</select>
	</td>
</tr>

<tr>
	<td valign=top align=right><b>Description: </b><br>(do not use HTML, please)</td>
	<td><textarea name=E_d rows=6 cols=32><?=$ae2[E_d]?> </textarea></td>
</tr>

<tr>
	<td align=center colspan=2>
	<input type=submit name=submit value="Save this and add another one">
	<input type=hidden name=En value=<?=$En?>>
	</td>
</tr>

<tr>
	<td align=center colspan=2>
	<input type=submit name=submit value="Save this and go to Step 3 (Skills)">
	<input type=hidden name=En value=<?=$En?>>
	</td>
</tr>

</table>
	
<?
}

?>
<? include_once('../footer.php'); ?>